<?php
class adik_asuh extends MY_Controller{
    function adik_asuh(){
        parent::MY_Controller();
        $this->data['title'] = "Master Data Adik Asuh";
        $this->load->model('m_adik_asuh');
        $this->load->model('m_kelas');
        $this->load->model('m_tahun_ajaran');
        $this->load->model('m_raport');
    }
    var $data;
    var $limit = 10;
    function index(){
        $this->get_adik_asuh('all','nama','asc',0);
    }
    function search(){
        $params = "nama_".$this->input->post('nama');
        $url = $this->input->post('url');
        redirect("$url/$params/0/");
    }
    function get_adik_asuh($params = 'all',$sortBy,$type = 'asc',$offset = 0){
        $option = parsing_param1($params);
        $this->data['searchLink'] = 'adik_asuh/get_adik_asuh';
        $this->data['content'] = "adik_asuh/v_adik_asuh";
        
        $uri_segment = 6;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_adik_asuh->getCountRows($option);
        $this->data['listAdikAsuh'] = $this->m_adik_asuh->getListAdikAsuh($offset,$this->limit,$option,$sortBy,$type);
        $config['base_url'] = site_url("adik_asuh/get_adik_asuh")."/".$params."/$sortBy/$type";
        $config['uri_segment'] = $uri_segment;
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        if($type == 'asc'){
            $type = 'desc';
        }else $type = 'asc';
        $this->data['sortNama'] = site_url("adik_asuh/get_adik_asuh/".$id)."/".$params."/nama/$type/$offset";
        $this->data['sortTglLahir'] = site_url("adik_asuh/get_adik_asuh/".$id)."/".$params."/tgl_lahir/$type/$offset";
        
        $this->render($this->data);
    }
    function add_adik_asuh_form($params = "all",$sortBy,$type = 'asc',$offset = 0){
        $option = parsing_param1($params);
        $this->data['searchLink'] = "adik_asuh/add_adik_asuh_form";
        
        $this->data['content'] = "adik_asuh/v_adik_asuh";
        $this->data['subLink'] = "adik_asuh/add_adik_asuh_proses";
        $this->data['formTitle'] = "Form Tambah Data Adik Asuh";
        $this->data['formView'] = "adik_asuh/addAdikAsuhForm";
        
        $uri_segment = 6;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_adik_asuh->getCountRows($option);
        $this->data['listAdikAsuh'] = $this->m_adik_asuh->getListAdikAsuh($offset,$this->limit,$option,$sortBy,$type);
        $this->data['listKelas'] = $this->m_kelas->getListKelas();
        $this->data['listTahunAjaran'] = $this->m_tahun_ajaran->getActiveTahunAjaran();
        $config['base_url'] = site_url("adik_asuh/add_adik_asuh_form")."/".$params."/$sortBy/$type";
        $config['uri_segment'] = $uri_segment;
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        if($type == 'asc'){
            $type = 'desc';
        }else $type = 'asc';
        $this->data['sortNama'] = site_url("adik_asuh/add_adik_asuh_form/".$id)."/".$params."/nama/$type/$offset";
        $this->data['sortTglLahir'] = site_url("adik_asuh/add_adik_asuh_form/".$id)."/".$params."/tgl_lahir/$type/$offset";
        
        $this->render($this->data);
    }
    function edit_adik_asuh_form($id,$params = "all",$sortBy,$type = 'asc',$offset = 0){
        $option = parsing_param1($params);
        $this->data['searchLink'] = "adik_asuh/edit_adik_asuh_form/$id";
        $this->data['sortLink'] = site_url("adik_asuh/edit_adik_asuh_form/".$id)."/".$params."/$sortBy/$type";
        
        $this->data['content'] = "adik_asuh/v_adik_asuh";
        $this->data['subLink'] = "adik_asuh/edit_adik_asuh_proses";
        $this->data['formTitle'] = "Form Edit Data Adik Asuh";
        $this->data['formView'] = "adik_asuh/editAdikAsuhForm";
        $this->data['dataInput'] = $this->m_adik_asuh->getAdikAsuhById($id);
        
        $uri_segment = 7;
        if($offset != 0){
          $offset = $this->uri->segment($uri_segment);  
        }
        $num_rows = $this->m_adik_asuh->getCountRows($option);
        $this->data['listAdikAsuh'] = $this->m_adik_asuh->getListAdikAsuh($offset,$this->limit,$option,$sortBy,$type);
        $this->data['listKelas'] = $this->m_kelas->getListKelas();
        $this->data['listTahunAjaran'] = $this->m_tahun_ajaran->getActiveTahunAjaran();
        $config['base_url'] = site_url("adik_asuh/edit_adik_asuh_form/".$id)."/".$params."/nama/$type";
        $config['uri_segment'] = $uri_segment;
        $config['total_rows'] = $num_rows;
        $config['per_page'] = $this->limit;
        $this->pagination->initialize($config);
        $this->data['pagination'] = $this->pagination->create_links();
        $this->data['offset'] = $offset;
        if($type == 'asc'){
            $type = 'desc';
        }else $type = 'asc';
        $this->data['sortNama'] = site_url("adik_asuh/edit_adik_asuh_form/".$id)."/".$params."/nama/$type/$offset";
        $this->data['sortTglLahir'] = site_url("adik_asuh/edit_adik_asuh_form/".$id)."/".$params."/tgl_lahir/$type/$offset";
        
        $this->render($this->data);
    }
    function add_adik_asuh_proses(){
        $insert = $this->m_adik_asuh->addAdikAsuh($_POST);
        if($insert == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("adik_asuh");
    }
    function edit_adik_asuh_proses(){
        $update = $this->m_adik_asuh->editAdikAsuh($_POST);
        if($update == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect("adik_asuh");
    }
    function detail_adik_asuh($id){
        $this->data['content'] = "adik_asuh/detailAdikAsuh";
        $this->data['listAdikAsuh'] = $this->m_adik_asuh->getAdikAsuhById($id);
        $this->data['linkBack'] = site_url('adik_asuh/get_adik_asuh');
        $this->data['titlePage'] = "Detail Adik Asuh";
        $this->data['subLink'] = "adik_asuh/add_dinamis_adik_asuh_proses";
        $this->data['dinamisAdikAsuh'] = $this->m_adik_asuh->getDinamisAdikAsuh($id);
        $this->data['raportSD'] = $this->m_adik_asuh->getRaport($id,1);
        $this->data['raportSMP'] = $this->m_adik_asuh->getRaport($id,2);
        $this->data['raportSMA'] = $this->m_adik_asuh->getRaport($id,3);
        
        $this->render($this->data);
    }
    function get_raport($id,$idTingkatPendidikan){
        $this->data['content'] = "adik_asuh/RaportAdikAsuh";
        $this->data['listRaport'] = $this->m_adik_asuh->getRaport($id,$idTingkatPendidikan);
        $this->data['adikAsuh'] = $this->m_adik_asuh->getAdikAsuhById($id);
        $this->data['linkBack'] = site_url("adik_asuh/detail_adik_asuh/$id");
        $this->data['titlePage'] = 'Raport Adik Asuh';
        $this->data['prevPage'] = 'Detail Adik asuh';
        
        $this->render($this->data);
    }
    function detail_raport($id,$idAdikAsuh,$uri){
        $this->data['linkBack'] = site_url("adik_asuh/get_raport/$idAdikAsuh/$uri");
        $this->data['titlePage'] = 'Detail Raport Adik Asuh';
        $this->data['prevPage'] = 'Raport Adik asuh';
        $this->data['content'] = "raport/raportInfo";
        $this->data['raportList'] = $this->m_raport->detailRaport($id);
        
        $this->render($this->data);
    }
    function add_dinamis_adik_asuh_proses(){
        $data = array('tanggal' => date('Y-m-d'),
            'id_adik_asuh' => $this->input->post('idAdikAsuh'),
            'alamat' => $this->input->post('alamat'),
            'no_telp' => $this->input->post('noTelp'),
            'jumlah_saudara' => $this->input->post('jumSaudara'),
            'id_sekolah' => $this->input->post('idSekolah'),
            'id_kelas' => $this->input->post('kelas'),
            'id_tahun_ajaran' => $this->input->post('id_tahun_ajaran'),
            'status' => '1');
        
        $insert = $this->m_adik_asuh->addDinamisAdikAsuh($data);
        if($insert == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        
        redirect('adik_asuh/detail_adik_asuh/'.$this->input->post('idAdikAsuh'));
    }
    function delete_adik_asuh($id){
        $delete = $this->m_adik_asuh->deleteAdikAsuh($id);
        if($delete == TRUE){
            $this->session->set_flashdata("message",3);
        }else{
            $this->session->set_flashdata("message",4);
        }
        
        redirect("adik_asuh");
    }
}
?>
